package com.xique.park.controller.web;

import com.xique.common.core.utils.SecurityUtils;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.core.web.domain.PageResult;
import com.xique.common.log.annotation.Log;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.park.bean.request.web.etcObu.EtcObuRequest;
import com.xique.park.service.service.IEtcObuRecService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ETC的OBU识别记录Controller
 *
 * @author wld
 * @date 2022/3/16 10:45
 */
@RequiredArgsConstructor
@RestController
@RequestMapping(value = "/web/etcObu")
public class WebEtcObuRecController {

    private final IEtcObuRecService etcObuRecService;

    /**
     * 分页查询ETC识别记录
     */
    @Log(title = "分页查询ETC识别记录")
    @PreAuthorize(hasPermi = "parking:identification:list")
    @PostMapping(value = "/list")
    public AjaxResult list(@RequestBody(required = false) EtcObuRequest etcObuRequest) {
        etcObuRequest = checkParam(etcObuRequest);
        PageResult result = etcObuRecService.selectPageList(etcObuRequest);
        return AjaxResult.success(result);
    }

    private EtcObuRequest checkParam(EtcObuRequest request) {
        if (request == null) {
            request = new EtcObuRequest();
        }
        int pageNum = request.getPageNum() == null ? 1 : request.getPageNum();
        int pageSize = request.getPageSize() == null ? 10 : request.getPageSize();
        if (request.getParkId() == null) {
            Long parkId = SecurityUtils.getParkId();
            if (parkId != null) {
                request.setParkId(parkId);
            }
        }
        request.setPageNum(pageNum);
        request.setPageSize(pageSize);
        return request;
    }

}
